package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ProductStock;
import cn.wolfcode.crm.query.ProductQueryObejct;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IProductStockService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/productStock")
public class ProductStockController {

    @Autowired
    private IProductStockService productStockService;

    @RequestMapping("")
    public String view(){

        return "productStock";
    }
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(@ModelAttribute("qo")ProductQueryObejct qo){

        PageResult result = productStockService.queryForList(qo);

        return result;
    }



    //盘点
    @RequestMapping("/audit")
    @ResponseBody
    public JsonResult audit(Long id){
        JsonResult result = new JsonResult();
        try {

            productStockService.auditNumber(id);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg(e.getMessage());
        }

        return result;
    }


    //更新库存数量
    @RequestMapping("/updateReviseNumber")
    @ResponseBody
    public JsonResult updateReviseNumber(ProductStock stock){
        JsonResult result = new JsonResult();
        try {
            productStockService.updateReviseNumber(stock);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg(e.getMessage());
        }
        return result;
    }

    //库存调拨
    @RequestMapping("/allocation")
    @ResponseBody
    public JsonResult allocation(ProductStock stock){
        JsonResult result = new JsonResult();
        try {
            productStockService.allocation(stock);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult(e.getMessage());
        }
        return result;
    }

    //
    @RequestMapping("/cahsier")
    public String cahsier(Model model, @ModelAttribute("qo")QueryObject qo){

        PageResult result = productStockService.queryForResult(qo);
        model.addAttribute("result",result);
        return "cashier";
    }
    @RequestMapping("/acceptMoney")
    public String acceptMoney(Model model, @ModelAttribute("qo")QueryObject qo){

        return "accept/acceptMoney";
    }



}
